var vote= new Vue({
    el : '#Votelist',
    data:{
        userId : $("#id").val(),
        xiangmuId:$("#xiangmuId").val(),
        xiangmuleixing:$("#xiangmuleixing").val(),
        detailid: "",
        pinzhong:"",
        pinpai:"",
        xiangmu : {},

        pinpailist:[],
        resultlist:[],

        syyz_value: [],

        show : false,
        total:0,
        tongyishu:0,
        butongyishu:0,
        checkAll: false,
        checkedCities: [],
        isIndeterminate: true,
        issubmited:false,

    },
    created : function() {
        var _this = this;

        $(".nav navbar-nav li").removeClass("active");
        $("#nav_biaojue").addClass("active");
        _this.findIsacticed();


    },

    methods : {
        openSelect() {
            console.log(123)
            this.$refs.selectRef.toggleMenu();
        },
        handleCheckAllChange(val) {
            var ids = this.shiyongyuanzelist.map(item => {
                return item.id
            })
            this.syyz_value = val ? ids : [];
            this.isIndeterminate = false;
            console.log(this.checkedCities)
        },
        handleCheckedCitiesChange(value) {
            var ids = this.shiyongyuanzelist.map(item => {
                return item.id
            })
            let checkedCount = value.length;
            this.checkAll = checkedCount === ids.length;
            this.isIndeterminate = checkedCount > 0 && checkedCount < ids.length;
            this.syyz_value = value
        },
        findIsacticed:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/xiangmu/getIsactivedxiangmu', {
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.xiangmu = data;
                        _this.xiangmuId=_this.xiangmu.xiangmuid;
                        _this.xiangmuleixing=_this.xiangmu.xiangmuleixing;
                        _this.getResultCount();
                        _this.checkIsSubmited();
                        _this.findBiaojuelist();

                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },

        syyzChange:function (val){
            this.syyz_value = val
        },
        findBiaojuelist:function (){
            var _this = this;
            layer.open({type:3});
            $.post("/jieguo/findBiaojuelist",{
                xiangmuid :_this.xiangmuId,
                xiangmuleixing :_this.xiangmuleixing,
                userid :_this.userId,
            },function(ppData){
                layer.closeAll("loading");
                if (ppData != null){
                    if(ppData.result == "1"){
                        var data=ppData.resultContent;
                        var mmHtml = "<div class='table-head'><table class=\"table table-hover table-bordered\" style=\"overflow:hidden; margin-bottom:10px;table-layout:fixed;\" v-if=\"show\" cellspacing=\"0\" cellpadding=\"0\">\n" +
                            "   <thead >\n" +
                            "    <tr style=\"font-weight: bold;\">\n" +
                            "       <td rowspan='2' style=\"text-align:center;vertical-align:middle;width:120px;\" >引进类型</td>\n" +
                            "       <td rowspan='2' style=\"text-align:center;vertical-align:middle;width:60px;\" >总序号</td>\n"
                            if(_this.xiangmuleixing=="19"){
                                mmHtml+= "       <td colspan='4' style=\"text-align:center;vertical-align:middle;\" >设备信息</td>\n"
                            }
                            if(_this.xiangmuleixing=="20"){
                                mmHtml+= "       <td colspan='6' style=\"text-align:center;vertical-align:middle;\" >设备信息</td>\n"
                            }

                            mmHtml+= "       <td colspan='9' style=\"text-align:center;vertical-align:middle;\" >配套耗材（试剂）信息</td>\n" +
                            "       <td rowspan='2' style=\"text-align:center;vertical-align:middle;width:60px;\" >国产/进口</td>\n" +
                            "       <td rowspan='2' style=\"text-align:center;vertical-align:middle;width:120px;\" >表决意见</td>\n" +
                            "    </tr>\n" +
                            "    <tr style=\"font-weight: bold;\">\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >设备名称</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >设备型号</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >设备来源</td>\n";
                            if(_this.xiangmuleixing=="19")
                            {
                                mmHtml+= "       <td style=\"text-align:center;vertical-align:middle;\" >设备品牌</td>\n"
                            }
                            if(_this.xiangmuleixing=="20")
                            {
                                mmHtml+= "       <td style=\"text-align:center;vertical-align:middle;\" >启用日期</td>\n" +
                                "       <td style=\"text-align:center;vertical-align:middle;\" >设备序列号</td>\n" +
                                "       <td style=\"text-align:center;vertical-align:middle;\" >设备生产厂家</td>\n"
                            }
                            mmHtml+=
                            "       <td style=\"text-align:center;vertical-align:middle;\" >平台编码</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >产品名称</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >规格</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >型号</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >注册证号</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >生产厂家</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >单位</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >单价</td>\n" +
                            "       <td style=\"text-align:center;vertical-align:middle;\" >医保编码</td>\n" +
                            "    </tr>\n" +
                            "   </thead></table></div><div class='table-body'><table style=\"table-layout: fixed;\"><tbody>";
                        if(data.Biaojuelist.length > 0){
                            _this.show = true;
                            _this.pinpailist=data.Biaojuelist;
                            _this.resultlist=data.Resultlist;

                            for (var i = 0; i < data.Biaojuelist.length; i++) {
                                var pinpaiOne = data.Biaojuelist[i];

                                var pinguilist = pinpaiOne.pinguilist;
                                var mmPinpaiHebingshu = pinpaiOne.pinpaihebinghang;
                                var mmPinzhong = pinpaiOne.zongxuhao;


                                var zongxuhao = pinpaiOne.zongxuhao;
                                var shebeimingcheng = pinpaiOne.shebeimingcheng;
                                var shebeixinghao = pinpaiOne.shebeixinghao;
                                var shebeilaiyuan = pinpaiOne.shebeilaiyuan;
                                var shebeipinpai = pinpaiOne.beizhu1;
                                var qiyongriqi = pinpaiOne.qiyongriqi;
                                var shebeixuliehao = pinpaiOne.shebeixuliehao;
                                var shebeishengchanchangjia = pinpaiOne.shebeishengchanchangjia;

                                for (var j = 0; j < pinguilist.length; j++) {
                                    var s=0;

                                    var pinguiOne = pinguilist[j];
                                    var id=pinguiOne.id;
                                    var result=pinguiOne.result;
                                    var ordernum = pinguiOne.ordernum;
                                    var yinjinleixing = pinguiOne.yinjinleixing;
                                    var pingtaibianma = pinguiOne.pingtaibianma;
                                    var chanpinmingcheng = pinguiOne.chanpinmingcheng;
                                    var guige = pinguiOne.guige;
                                    var xinghao = pinguiOne.xinghao;
                                    var zhucezhenghao = pinguiOne.zhucezhenghao;
                                    var shengchanchangjia = pinguiOne.shengchanchangjia;
                                    var danwei = pinguiOne.danwei;
                                    var danjia = pinguiOne.danjia;
                                    var yibaobianma = pinguiOne.yibaobianma;
                                    var guochanjinkou = pinguiOne.guochanjinkou;
                                    var beizhu = pinguiOne.beizhu;
                                    var shenqingkeshi = pinguiOne.shenqingkeshi;
                                    var mmPinpai = pinguiOne.ordernum;
                                    var isvote = pinguiOne.isvote;

                                    var mmHuanhangfu = "";
                                    var mmyijihe="";

                                    var yibaocolor = ""
                                    if(yibaobianma!="无"&&yibaobianma!=""){
                                        yibaocolor = "background-color: #67c23a6b;"
                                    }

                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width: 120px;'>" + yinjinleixing + "</td>";

                                    if(j==0 &&s==0){
                                        mmyijihe+= "<td style='text-align:center;vertical-align:middle;width: 60px;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + zongxuhao + "</td>";
                                        mmyijihe+= "<td style='text-align:center;vertical-align:middle;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + shebeimingcheng + "</td>";
                                        mmyijihe+= "<td style='text-align:center;vertical-align:middle;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + shebeixinghao + "</td>";
                                        mmyijihe+= "<td style='text-align:center;vertical-align:middle;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + shebeilaiyuan + "</td>";
                                        if(_this.xiangmuleixing==20){
                                            mmyijihe += "<td style='text-align:center;vertical-align:middle;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + qiyongriqi + "</td>";
                                            mmyijihe +=
                                            "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                            "  white-space: normal;\n" +
                                            "  word-wrap: break-word;\n" +
                                            "  -webkit-line-clamp: 3;\n" +
                                            "  -webkit-box-orient: vertical;'title='" + shebeixuliehao + "' " +
                                            "rowspan='" + mmPinpaiHebingshu + "'>" + shebeixuliehao + "</a></td>";
                                            mmyijihe += "<td style='text-align:center;vertical-align:middle;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + shebeishengchanchangjia + "</td>";
                                        }
                                        if(_this.xiangmuleixing==19){
                                            mmyijihe += "<td style='text-align:center;vertical-align:middle;height: 100%'  rowspan='" + mmPinpaiHebingshu + "'>" + shebeipinpai + "</td>";
                                        }
                                        s= 1;
                                    }
                                    mmHtml +=mmyijihe;
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + pingtaibianma + "'>" + pingtaibianma + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;'>" + chanpinmingcheng + "</td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + guige + "'>" + guige + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + xinghao + "'>" + xinghao + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + zhucezhenghao + "'>" + zhucezhenghao + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + shengchanchangjia + "'>" + shengchanchangjia + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + danwei + "'>" + danwei + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + danwei + "'>" + danjia + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;"+ yibaocolor + "white-space:nowrap;text-overflow: ellipsis; overflow: hidden;'><a style='text-align:center;vertical-align:middle;white-space:nowrap;text-overflow: ellipsis; overflow: hidden;display: -webkit-box;\n" +
                                        "  white-space: normal;\n" +
                                        "  word-wrap: break-word;\n" +
                                        "  -webkit-line-clamp: 3;\n" +
                                        "  -webkit-box-orient: vertical;'title='" + yibaobianma + "'>" + yibaobianma + "</a></td>";
                                    mmHtml += "<td style='text-align:center;vertical-align:middle;width: 60px;'>" + guochanjinkou + "</td>";

                                    var mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;\"></div>";
                                    if(result==null&&isvote){
                                        mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;width:108px;\"> <span  style=\"color:blue\">未表决</span></div>";
                                    }
                                    if(result==1&&isvote){
                                        mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;width:108px;\"><span  style=\"color:green\">同意</span></div>";
                                    }
                                    if(result==0&&isvote){
                                        mmMsgDiv="<div id='div_"+mmPinzhong+"_"+mmPinpai+"' style=\"text-align:center;width:108px;\"> <span  style=\"color:#ff0000\">不同意</span></div>";
                                    }
                                    if(!_this.issubmited&&isvote){
                                        var mmBtndiv = "<div style=\"text-align:center;\"><input type=\"button\" class=\"btn btn-sm btn-success\" style=\"float: left;width:108px;\" value=\"同 意\" onclick=\"toVote('" + id + "','" + mmPinzhong + "','" + mmPinpai + "',1)\">"
                                            + "<input type=\"button\" class=\"btn btn-sm btn-danger\" style=\"float: left;width:108px;\" value=\"不同意\" onclick=\"toVote('" + id + "','" + mmPinzhong + "','" + mmPinpai + "',0)\"></div>";
                                    }else {
                                        var mmBtndiv =""
                                    }
                                    mmHtml +="<td style='text-align:center;vertical-align:middle;width:120px;height: 100%'" + mmPinpaiHebingshu + ">"+mmMsgDiv+"" + mmBtndiv + "</td>";
                                    mmHtml += "</tr>";

                                }
                            }

                        }else {
                            _this.show = false;
                        }
                        mmHtml += "</table>";
                        $("#List").html(mmHtml);
                    }else{
                        layer.alert(ppData.message);
                    }
                }

            },"json");
        },
        getResultCount:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/jieguo/getResultCount', {
                xiangmuid :_this.xiangmuId,
                xiangmuleixing :_this.xiangmuleixing,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        var data = ppData.resultContent;
                        _this.tongyishu=data.tongyiShu;
                        _this.total=data.total;
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        toVoteAll:function (ppresult){

            var _this = this;
            var mmMessage="";
            if("0"==ppresult){
                mmMessage="确定全部不同意当前表决项？";
            }else if("1"==ppresult){
                mmMessage="确定全部同意当前表决项？";
            }
            layer.confirm(mmMessage,{
                btn : ['是','否']
            },function(){
                layer.open({type:3});
                $.post("/jieguo/toupiao_all", {
                    xiangmuid :_this.xiangmuId,
                    userid :_this.userId,
                    result:ppresult,
                    random : Math.random()
                }, function(ppData) {
                    if (ppData != null) {
                        layer.closeAll("loading");

                        if(ppData.result != "1"){
                            layer.alert(ppData.message);
                        }else{
                            layer.open({
                                time:1000,
                                btn:[],
                                content:"操作成功!",
                            });
                            window.location.reload();

                        }
                    }
                },"json");
            })
        },
        checkIsSubmited:function (){
            var _this = this;
            layer.open({type:3});
            $.post('/renyuanfenpei/checkIsSubmited', {
                xiangmuid :_this.xiangmuId,
                userid :_this.userId,
                rdm : Math.random()
            },function(ppData) {
                layer.closeAll("loading");
                if(ppData != null){
                    if(ppData.result == "1"){
                        if(ppData.resultContent=="1"){
                            _this.issubmited=true;
                        }
                    }else{
                        layer.alert(ppData.message);
                    }
                }
            },"json");
        },
        tosubmit:function (){
            var _this = this;
            layer.confirm("请核对信息，提交之后不能修改吗？",{
                btn : ['是','否']
            },function(){
                layer.open({type:3});
                $.ajaxSettings.async = false;
                var m = false
                $.post("/jieguo/findBiaojuelist",{
                    xiangmuid: _this.xiangmuId,
                    xiangmuleixing: _this.xiangmuleixing,
                    userid: _this.userId
                }, function(ppData){
                    layer.closeAll("loading");
                    if (ppData != null){
                        if(ppData.result == "1") {
                            var array = ppData.resultContent.Resultlist;
                            for(var item of array){
                                if(item.result == null){
                                    layer.alert("序号" + item.ordernum + "未表决");
                                    m= true;
                                    return
                                }
                            }
                            layer.closeAll("loading");
                            m= false
                        }
                    }
                },"json");
                if(m)return
                $.ajaxSettings.async = true;

                $.post('/yiyongjieguo/submit', {
                    xiangmuid :_this.xiangmuId,
                    userid :_this.userId,
                    rdm : Math.random()
                },function(ppData) {
                    if(ppData != null){
                        if(ppData.result == "1"){
                            _this.issubmited=true;
                            layer.alert("提交成功");
                            _this.findIsacticed();
                            _this.findBiaojuelist();
                        }else{
                            layer.alert(ppData.message);
                        }
                    }
                },"json");
            })
        },




    },
})